package ru.spies.forms;

import javax.servlet.http.Cookie;

import ru.spies.content.AddContent;
import ru.spies.content.SystemContent;

public class AddForm extends FormCreator {
	
	private static AddForm statThis;
	
	private static final String ADD_FORM_FUNC_NAMES_ARRAY[]={
		"Добавить новый документ","Добавить новое задание ","Дать задание агенту",
		"Добавить нового агента", "Добавить новый отдел","Добавить новую страну",
		"Добавить новый тип секретности","Добавить новый тип заданий"
	};
	
	private AddForm() {
		setCookieName(LastCookies.COOKIE_NAME_FORM_FOR_WORK);
	}
	
	public static AddForm getInstance(){
		if (statThis==null){
			statThis = new AddForm();
		}
		return statThis;
	}
	
	@Override
	protected ICookie childCookieWork(Cookie cookie) {
		if (Integer.valueOf(cookie.getValue())==EDBTables.COUNTRY.ordinal()){
			return EDBTables.COUNTRY;
		}
		if (Integer.valueOf(cookie.getValue())==EDBTables.AGENT.ordinal()){
			return EDBTables.AGENT;
		}
		if (Integer.valueOf(cookie.getValue())==EDBTables.DEPARTMENT.ordinal()){
			return EDBTables.DEPARTMENT;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.AGENT_AND_TASK.ordinal()){
			return EDBTables.AGENT_AND_TASK;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.DOCUMENT.ordinal()){
			return EDBTables.DOCUMENT;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.IMPORTANCE.ordinal()){
			return EDBTables.IMPORTANCE;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.TASK.ordinal()){
			return EDBTables.TASK;
		}	
		if (Integer.valueOf(cookie.getValue())==EDBTables.TASK_TYPE.ordinal()){
			return EDBTables.TASK_TYPE;
		}		
		return null;
	}

	@Override
	protected String workWithCookieValue(ICookie cook) {
		EDBTables func = (EDBTables) cook;
		LastCookies.getInstance().setLastTable(func);
		switch (func) {
		case COUNTRY:
			return createAddCountryForm();
		case AGENT:
			return createAddAgentForm();
		case AGENT_AND_TASK:
			return createAddAgentAndTaskForm();
		case DEPARTMENT:
			return createAddDepartmentForm();
		case DOCUMENT:
			return createAddDocumentForm();
		case IMPORTANCE:
			return createAddImportanceForm();
		case TASK:
			return createAddTaskForm();
		case TASK_TYPE:
			return createAddTaskTypeForm();
		default:
			return createForm(SOME_ERRORS);
		}
	}
	
	public String createAddCountryForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddCountryContent(),SHOW_RESULT_LINK);
	}
	
	public String createAddDepartmentForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddDepartmentContent(),SHOW_RESULT_LINK);
	}

	public String createAddAgentForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddAgentContent(), SHOW_RESULT_LINK);
	}

	public String createAddAgentAndTaskForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddAgentAndTaskContent(), SHOW_RESULT_LINK);
	}

	public String createAddDocumentForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddDocumentContent(), SHOW_RESULT_LINK);
	}

	public String createAddTaskForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddTaskContent(), SHOW_RESULT_LINK);
	}

	public String createAddImportanceForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddImportanceContent(), SHOW_RESULT_LINK);
	}

	public String createAddTaskTypeForm(){
		return createFormWithPostMethod(AddContent.getInstance().formAddTaskTypeContent(), SHOW_RESULT_LINK);
	}

	@Override
	public String createThisForm() {
		return createForm(SystemContent.getInstance().formForWorkContent(ADD_FORM_FUNC_NAMES_ARRAY));
	}

}
